home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / PORTABLE.H < prev    next >
Text File  |  1993-04-05  |  5KB  |  144 lines

  1. /*============================================================================
  2.  
  3.     portable.h   v1.00      Written by Scott Robert Ladd.
  4.  
  5.     _MSC_VER        Microsoft C 6.0 and later
  6.     _QC             Microsoft Quick C 2.51 and later
  7.     __TURBOC__      Borland Turbo C and Turbo C++
  8.     __ZTC__         Zortech C and C++
  9.     __WATCOM__      WATCOM C
  10. ============================================================================*/
  11.  
  12.  
  13. /* prevent multiple inclusions of this header file */
  14.  
  15. #if !defined(PORTABLE_H)
  16. #define PORTABLE_H
  17.  
  18. /*----------------------------------------------------------------------------
  19.     Pointer-related macros
  20.  
  21.     MK_FP   creates a far pointer from segment and offset values
  22. ----------------------------------------------------------------------------*/
  23.  
  24. #if !defined(MK_FP)
  25.     #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  26. #endif
  27.  
  28. /*----------------------------------------------------------------------------
  29.     Directory search macros and data structures
  30.  
  31.     DOSFileData         MS-DOS file data structure
  32.     FIND_FIRST          MS-DOS function 0x4E -- find first file matchine spec
  33.     FIND_NEXT           MS-DOS function 0x4F -- find subsequent files
  34. ----------------------------------------------------------------------------*/
  35.  
  36. /* make sure the structure is packed on byte boundary */
  37.  
  38. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  39.     #pragma pack(1)
  40. #elif defined(__ZTC__)
  41.     #pragma ZTC align 1
  42. #elif defined(__TURBOC__)
  43.     #pragma option -a-
  44. #endif
  45.  
  46. /* use this structure in place of compiler-defined file structure */
  47.  
  48. typedef struct {
  49.       char        reserved[21];
  50.       char        attrib;
  51.       unsigned    time;
  52.       unsigned    date;
  53.       long        size;
  54.       char        name[13];
  55.       } DOSFileData;
  56.  
  57. /* set structure alignment to default */
  58.  
  59. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  60.  #pragma pack()
  61. #elif defined (__ZTC__)
  62.  #pragma ZTC align
  63. #elif defined (__TURBOC__)
  64.  #pragma option -a.
  65. #endif
  66.  
  67. /* include proper header files and create macros */
  68.  
  69. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC)
  70.  #include "direct.h"
  71.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr,\
  72.        (struct find_t *)buf)
  73.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  74. #elif defined (__TURBOC__)
  75.  #include "dir.h"
  76.  #define FIND_FIRST(spec,attr,buf) findfirst(spec,(struct ffblk *)buf,attr)
  77.  #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  78. #elif defined (__ZTC__)
  79.  #include "dos.h"
  80.  #define FIND_FIRST(spec,attr,buf) dos_findfirst(spec,attr,\
  81.        (struct DOS_FIND *)buf)
  82.  #define FIND_NEXT(buf) dos_findnext((struct DOS_FIND *)buf)
  83. #endif
  84.  
  85. /*----------------------------------------------------------------------------
  86.     I/O Port Macros
  87.  
  88.     IN_PORT     read byte from I/O port
  89.     IN_PORTW    read word from I/O port
  90.     OUT_PORT    write byte to I/O port
  91.     OUT_PORTW   write word to I/O port
  92. ----------------------------------------------------------------------------*/
  93.  
  94. #if defined(__TURBOC__)
  95.  #include "dos.h"
  96.  #define IN_PORT(port)           inportb(port)
  97.  #define IN_PORTW(port)          inport(port)
  98.  #define OUT_PORT(port, val)     outportb(port, val)
  99.  #define OUT_PORTW(port, val)    outport(port, val)
  100. #else
  101.  #include "conio.h"
  102.  
  103.  #define IN_PORT(port)           inp(port)
  104.  #define IN_PORTW(port)          inpw(port)
  105.  #define OUT_PORT(port, val)     outp(port, val)
  106.  #define OUT_PORTW(port, val)    outpw(port, val)
  107.  
  108. /*----------------------------------------------------------------------------
  109.     Borland pseudo register macros
  110.  
  111.     These macros replace references to Borland's pseudo register
  112.     variables and geninterrup() funciton with traditional struct
  113.     REGS/int86 references.
  114. ----------------------------------------------------------------------------*/
  115.  
  116. #if !defined(__TURBOC__)
  117.  #include "dos.h"
  118.  
  119.  union REGS CPURegs;
  120.  
  121.  #define _AX CPURegs.x.ax
  122.  #define _BX CPURegs.x.bx
  123.  #define _CX CPURegs.x.cx
  124.  #define _DX CPURegs.x.dx
  125.  
  126.  #define _AH CPURegs.x.ah
  127.  #define _AL CPURegs.x.al
  128.  #define _BH CPURegs.x.bh
  129.  #define _BL CPURegs.x.bl
  130.  #define _CH CPURegs.x.ch
  131.  #define _CL CPURegs.x.cl
  132.  #define _DH CPURegs.x.dh
  133.  #define _DL CPURegs.x.dl
  134.  
  135.  #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);
  136.  #define O_DENYALL   0x10
  137.  #define O_DENYWRITE 0x20
  138.  #define O_DENYREAD  0x30
  139.  #define O_DENYNONE  0x40
  140. #endif
  141.  
  142. #endif
  143. #endif
  144.